package cn.xo68.boot.auth.server.mapper;


import cn.xo68.boot.auth.server.domain.OauthRole;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * OauthRole mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月28日 11:04:12
 *
 */
public interface OauthRoleMapper {


	@Select("SELECT * FROM oauth_role WHERE role_id = #{roleId}")
    @Results(value = {
    @Result(id = true, column = "role_id", property = "roleId"),
        @Result(column = "role_name", property = "roleName"),
        @Result(column = "role_description", property = "roleDescription"),
        @Result(column = "operator_id", property = "operatorId"),
        @Result(column = "operator_name", property = "operatorName"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    OauthRole get(@Param("roleId") String roleId);
	
	@Select("SELECT * FROM oauth_role WHERE role_id = #{roleId}")
    @Results(value = { 
    @Result(id = true, column = "role_id", property = "roleId"),
        @Result(column = "role_name", property = "roleName"),
        @Result(column = "role_description", property = "roleDescription"),
        @Result(column = "operator_id", property = "operatorId"),
        @Result(column = "operator_name", property = "operatorName"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    OauthRole find(@Param("roleId") String roleId);
	
	@Select("SELECT * FROM oauth_role order by update_time desc")
    @Results(value = { 
    @Result(id = true, column = "role_id", property = "roleId"),
        @Result(column = "role_name", property = "roleName"),
        @Result(column = "role_description", property = "roleDescription"),
        @Result(column = "operator_id", property = "operatorId"),
        @Result(column = "operator_name", property = "operatorName"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    List<OauthRole> list();
	
	@Insert("insert into oauth_role (role_id ,role_name ,role_description ,operator_id ,operator_name ,create_time ,update_time ) values (#{roleId} , #{roleName} , #{roleDescription} , #{operatorId} , #{operatorName} , #{createTime} , #{updateTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "roleId")
    void insert(OauthRole oauthRole);
	
	@Update("update oauth_role set  role_name=#{roleName}, role_description=#{roleDescription}, operator_id=#{operatorId}, operator_name=#{operatorName}, update_time=#{updateTime} where role_id = #{roleId}")
    void update(OauthRole oauthRole);

	@Delete("delete FROM oauth_role WHERE role_id = #{roleId}")
	void delete(@Param("roleId") String roleId);
}